﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Configuration;
using System.Data;
using System.Text;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using Rison.Web.Common;
using Rison.BusinessFacade.Helper;
using Rison.BusinessFacade.Common;
using Rison.BusinessFacade.Entity.NRBZ;
using Rison.BusinessFacade.Facade.NRBZ;
using Rison.DataAccess.Common;

namespace Rison.Web.CommonPage.FileUploader
{
    public partial class TestUpload : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string val = Request.Params["fileupload1_hdnFileVal"];
            NewUpload(val);


            string val1 = Request.Params["fileupload2_hdnFileVal"];


        }

        public List<SysAttachment> NewUpload(string sFilePath)
        {
            
            List<SysAttachment> attList = new List<SysAttachment>();
            SysAttachment att = new SysAttachment();
            string[] a = sFilePath.Split(',');
            for (int i = 0; i < a.Length; i++)
            {
                string[] b = a[i].Split(';');
                if (b.Length > 1)
                {
                    string tmpVirtualPath = HttpContext.Current.Server.MapPath(b[0].ToString());
                    FileInfo f = new System.IO.FileInfo(tmpVirtualPath);
                    att = new SysAttachment();
                    att.FileName = b[1].ToString();
                    att.FilePath = f.Name;
                    att.FileSize = f.Length.ToString();
                    att.Extension = f.Extension;
                    attList.Add(att);

                    string fileName = HttpContext.Current.Server.MapPath(GlobalParams.Instance.AttachmentUploadUrl) + f.Name;
                    if (!File.Exists(fileName))
                    {
                        f.MoveTo(fileName);
                    }
                }
            }
            return attList;

        }
    }
}
